<template>
	<view class="container">
		<view class="qrCode" v-if="src">
			<image :src="src" mode="aspectFill" show-menu-by-longpress></image>
		</view>
		<view class="no-qrCode" v-else>
			<image src="/static/images/index/no-wx.png" mode=""></image>
		</view>
		<view class="wx-text" v-if="src" >长按二维码识别</view>
		<uv-loading-page :loading="loading" loading-mode="spinner"></uv-loading-page>
	</view>
</template>

<script>
	import {
		toast
	} from '@/utils/common';
	import {
		getWxSchemeInfo,
		getAlternativeSuppliers,
		getMerchantH5Info
	} from '@/common/api.js'
	const app = getApp();
	export default {
		data() {
			return {
				src: "",
				deviceId: '',
				loading: false
			};
		},
		onLoad(e) {
			this.loading = true
			getAlternativeSuppliers({
				deviceCode: e.deviceId
			}).then((res) => {
				getMerchantH5Info({
					merchantId: res.data.id
				}).then((ress) => {
					console.log(ress.data);
					this.src = ress.data.merchantInfo.storeManagerWechat
					this.loading = false
				})
			})
		},
		methods: {
			leftClick() {
				app.navigateBack()
			},
			onConnect() {
				getWxSchemeInfo({
					"path": "pages/home/home",
					"query": `name=${this.name}&password=${this.password}`,
					"env_version": "trial"
				}).then(res => {
					console.log(res);
					if (res.data.openlink) {
						window.location.href = res.data.openlink
					}
				}).catch(err => {
					console.log(err);
				})
			}
		}
	}
</script>

<style lang="scss">
	.container {
		min-height: 100vh;
		width: 100vw;
		padding-top: 354rpx;
		box-sizing: border-box;
		background: radial-gradient(128% 128% at 95% 0%, #D7CEFF 0%, #BBE1FF 62%, #FFFFFF 95%);

		.qrCode {
			display: flex;
			align-items: center;
			justify-content: center;
			margin: 0 auto;
			margin-top: 90rpx;
			width: 360rpx;
			height: 363rpx;
			background: #FFFFFF;
			border-radius: 32rpx;

			image {
				height: 320rpx;
				width: 320rpx;
			}
		}

		.no-qrCode {
			height: 258rpx;
			width: 322rpx;
			margin: 0 auto;
			margin-top: 130rpx;

			image {
				height: 100%;
				width: 100%;
			}
		}

		.button {
			width: 300rpx;
			height: 96rpx;
			background: linear-gradient(180deg, #886AE6 0%, #4635FF 99%);
			border-radius: 48rpx;
			font-weight: 400;
			font-size: 32rpx;
			color: #FFFFFF;
			line-height: 96rpx;
			text-align: center;
			margin: 0 auto;
			margin-top: 40rpx;
		}

		.advertisement {
			width: calc(100vw - 40rpx);
			height: 216rpx;
			background: #a9a9a9;
			border-radius: 48rpx;
			position: fixed;
			bottom: 32rpx;
			left: 50%;
			transform: translateX(-50%);
		}
		.wx-text{
			font-weight: 400;
			font-size: 32rpx;
			color: #000000;
			line-height: 48rpx;
			text-align: center;
			margin-top: 40rpx;
		}
	}
</style>